package teams

import (
	"itodo/core/dao/table"
	"itodo/core/dao/teamdao"
	"itodo/core/localwrap"
)

var logTeamUsers = localwrap.GetLogger().Fork("itodo/core/service/teams", "TeamUsers")

type TeamUsers struct{}

func (s TeamUsers) Query(param teamdao.TeamUsersQueryParam) ([]table.TeamUser, int64) {
	logTeamUsers.Debug().Func("Query").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return teamdao.TeamUsers{RedisedMysql: d}.Query(param)
}

func (s TeamUsers) Get(id int) table.TeamUser {
	logTeamUsers.Debug().Func("Get").Int("id", id).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return teamdao.TeamUsers{RedisedMysql: d}.Get(id)
}

func (s TeamUsers) Add(param teamdao.TeamUsersAddParam) table.TeamUser {
	logTeamUsers.Debug().Func("Add").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return teamdao.TeamUsers{RedisedMysql: d}.Add(param)
}

func (s TeamUsers) Update(param teamdao.TeamUsersUpdateParam) {
	logTeamUsers.Debug().Func("Update").Interface("param", param).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	teamdao.TeamUsers{RedisedMysql: d}.Update(param)
}

func (s TeamUsers) Delete(id int) {
	logTeamUsers.Debug().Func("Delete").Int("id", id).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	teamdao.TeamUsers{RedisedMysql: d}.Delete(id)
}

//GetByTeamIdUid
func (s TeamUsers) GetByTeamIdUid(teamId, uid int) table.TeamUser {
	logTeamUsers.Debug().Func("GetByTeamIdUid").Int("teamId", teamId).Int("uid", uid).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return teamdao.TeamUsers{RedisedMysql: d}.GetByTeamIdUid(teamId, uid)
}

//GetByTeamIdUid
func (s TeamUsers) ListByUid(uid int) []table.TeamUser {
	logTeamUsers.Debug().Func("ListByUid").Int("uid", uid).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return teamdao.TeamUsers{RedisedMysql: d}.ListByUid(uid)
}

//ListByTeamId
func (s TeamUsers) ListByTeamId(teamId int) []table.TeamUser {
	logTeamUsers.Debug().Func("ListByUid").Int("teamId", teamId).Send()
	d := localwrap.GetRedisedMysql()
	defer d.Close()
	return teamdao.TeamUsers{RedisedMysql: d}.ListByTeamId(teamId)
}
